package com.wave.system.util;

import com.wave.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class StringSplitUtil {
    /**
     * 字符串切割长度
     */
    private final static int SPLIT_LENGTH = 26;

    /**
     * 实际所需字符串长度
     */
    private final static int REAL_LENGTH = 18;

    /**
     * 根据长度截取字符串
     * @param str
     * @return
     */
    public static List<String> splitStr(String str) {
        List<String> list = new ArrayList<>();
        int start = 0;
        while (start < str.length()) {
            int end = Math.min(start + SPLIT_LENGTH, str.length());
            list.add(str.substring(start, end).trim());
            start += SPLIT_LENGTH;
        }
        List<String> finalList = new ArrayList<>();
        for (String splitStr : list) {
            if (StringUtils.isEmpty(splitStr)){
                finalList.add(splitStr);
            }else {
                //log.info("splitStr:{},len:{}",splitStr,splitStr.length());
                finalList.add(splitStr.substring(0,REAL_LENGTH));
            }
        }
        return finalList;
    }
}
